﻿@using Novagoal.Website.Models.Views
@using Novagoal.Website.WebApp.Helpers
@using Novagoal.Utils

@model UsersViewModel
@{
    ViewBag.Title = string.Format("Novagoal | {0} Usuario", Model.UserId == 0 ? "Nuevo" : "Editar");
    Layout = "~/Views/Shared/MasterLayout.cshtml";
}
@section PageContent {
    <div class="main-content ui-corner-top">
        <div class="ui-widget-header ui-corner-all">
            <div class="title">@string.Format("{0} Usuario", Model.UserId == 0 ? "Nuevo" : "Editar")</div>
        </div>
        @{Html.RenderPartial("SubmitResults"); }
        <div class="ui-widget-content ui-corner-bottom">
            @using (Html.BeginForm("Save", "Users", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                <input type="hidden" id='UserId' name='UserId' value='@Model.UserId' />
                <input type="hidden" id='PersonId' name='PersonId' value='@Model.PersonId' />
                <fieldset class='formContent'>
                <legend>Informacion Personal</legend>
                    <div class='formColumn'>
                        @Html.Label("Nombre *")
                        @Html.TextBoxFor(model => model.FirstName)
                        <br />
                        @Html.Label("Apellido *")
                        @Html.TextBoxFor(model => model.LastName)
                        <br />
                        @Html.Label("Correo electronico *")
                        @Html.TextBoxFor(model => model.EmailAddress)
                        <br />
                        @Html.Label("Genero *")
                        @Html.DropDownList("Gender", new SelectList(Enum.GetValues(typeof(Enums.Gender)), Model.Gender))
                        <br />
                        @Html.Label("Lenguaje *")
                        @Html.DropDownList("Language", new SelectList(Enum.GetValues(typeof(Enums.Language)), Model.Language))
                        <br />
                        @Html.Label("Rol *")
                        @{var roleId = Model.Role != null ? Model.Role.Id : 0;}                  
                        @Html.DropDownList("RoleId", new SelectList(Model.Roles, "Id", "Name", roleId), "Select one")
                    </div>
                    <div class='formColumn'>
                        @Html.Label("Foto")
                        <input type="file" name="Avatar" id="Avatar" onchange="preview(this)" />
                        <br />
                        <div style='margin-left:150px'>
                            @Html.GetAvatar(Model.PersonId, new { height = "100px", id = "AvatarPreview" })
                        </div>
                    </div>
                </fieldset>
                <br />
                <div style='text-align:center'>
                    <label for="submit"></label>
                    <input type="submit" value="Guardar" class='button' />
                </div>
            }
        </div>
    </div>

    <script type="text/javascript">

        function preview(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#AvatarPreview')
                        .attr('src', e.target.result)
                        .height(100);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
}
